$(function () {
  //  2025-01-08 start
  // 教师学科占比字典
  var _projectList = {
    书法: '书法',
    体育: '体育',
    信息: '信息技术',
    其他: '其他',
    劳技: '劳技',
    化学: '化学',
    历史: '历史',
    历社: '历史与社会',
    地理: '地理',
    德育: '德育',
    心理: '心理健康',
    思品: '思想品德',
    思政: '思想政治',
    政治: '政治',
    数学: '数学',
    物理: '物理',
    特教: '特殊教育',
    珠宝: '珠宝',
    生物: '生物',
    电子: '电子',
    电商: '电子商务',
    科学: '科学',
    积心: '积极心理活动课',
    综实: '综合实践',
    美术: '美术',
    职教: '职业教育',
    艺术: '艺术',
    英语: '英语',
    语文: '语文',
    道法: '道德与法治',
    音乐: '音乐',
  }
  //  2025-01-08 end

  // 获取当前日期时间
  var headDate = $('#headDate')
  var headTime = $('#headTime')
  var dateTimer = null
  updateDate()
  clearInterval(dateTimer)
  dateTimer = setInterval(function () {
    updateDate()
  }, 500)
  function updateDate() {
    var date = new Date()
    var month = date.getMonth() + 1
    var currentMonth = month > 9 ? month : '0' + month
    var year = date.getFullYear()
    var day = date.getDate()
    var week = date.getDay()
    var hours = date.getHours()
    var minutes = date.getMinutes()
    var seconds = date.getSeconds()
    var weekInfo = {
      0: '天',
      1: '一',
      2: '二',
      3: '三',
      4: '四',
      5: '五',
      6: '六',
    }
    var dateVal =
      year + '年' + currentMonth + '月' + (day > 9 ? day : '0' + day) + '日'
    // ' 星期' +
    // weekInfo[week]
    var timeVal =
      ' ' +
      hours +
      ':' +
      (minutes > 9 ? minutes : '0' + minutes) +
      ':' +
      (seconds > 9 ? seconds : '0' + seconds)
    headDate.html(dateVal)
    headTime.html(timeVal)
    // console.log(dateVal + timeVal)
  }

  var yearSelect = $('#yearSelect')
  yearSelect.change(function () {
    console.log(yearSelect.val())
  })

  // 基础信息、在编教师情况
  var baseListLoading = $('#baseListLoading')
  var teacherNum = $('#teacherNum')
  var schoolNum = $('#schoolNum')
  var orgRatio = $('#orgRatio')
  var zbTeacherNum = $('#zbTeacherNum')
  var fzbTeacherNum = $('#fzbTeacherNum')
  var zbTeacherNav = $('#zbTeacherNav')
  var fzbTeacherNumNav = $('#fzbTeacherNumNav')
  var teacherTotal = $('#teacherTotal')
  var xxgg = $('#xxgg')
  var xxfgg = $('#xxfgg')
  var xxggNav = $('#xxggNav')
  var xxfggNav = $('#xxfggNav')
  var xxTeacherNum = $('#xxTeacherNum')
  var zxgg = $('#zxgg')
  var zxfgg = $('#zxfgg')
  var zxggNav = $('#zxggNav')
  var zxfggNav = $('#zxfggNav')
  var zxTeacherNum = $('#zxTeacherNum')
  var orgRatioVal = 0
  var baseInfo = {}
  var teacherCoreChartLoading = $('#teacherCoreChartLoading')
  var teacherYearListLoading = $('#teacherYearListLoading')
  getBaseTeacherInfo()
  function getBaseTeacherInfo() {
    baseListLoading.show()
    teacherCoreChartLoading.show()
    teacherYearListLoading.show()
    _post(
      'szpz_jllg_basicinfo',
      {},
      function (result) {
        baseListLoading.hide()
        teacherCoreChartLoading.hide()
        teacherYearListLoading.hide()
        console.log('基础信息', result)
        if (result.status !== 200) return
        baseInfo = result
        var list = result.data[0]
        schoolNum.empty()
        teacherNum.empty()
        orgRatio.empty()
        list[2] = list[2] + ''
        list[5] = list[5] + ''
        list[10] = list[10] + ''
        for (var i = 0; i < list[2].length; i++) {
          var item = list[2][i]
          schoolNum.append('<span>' + item + '</span>')
        }
        for (var i = 0; i < list[5].length; i++) {
          var item = list[5][i]
          teacherNum.append('<span>' + item + '</span>')
        }
        orgRatioVal = list[10]
        for (var i = 0; i < list[10].length; i++) {
          var item = list[10][i]
          orgRatio.append('<span>' + item + '</span>')
        }
        if (+list[7] < 30) {
          fzbTeacherNum.addClass('disabled')
        }
        teacherTotal.html(list[5])
        zbTeacherNum.html(list[6] + '%(' + list[3] + ')')
        fzbTeacherNum.html(list[7] + '%(' + list[4] + ')')
        zbTeacherNav.css('width', list[6] + '%')
        zbTeacherNum.css('width', list[6] + '%')
        fzbTeacherNumNav.css('width', list[7] + '%')
        fzbTeacherNum.css('width', list[7] + '%')
        xxgg.html('骨干：' + list[13] + '%(' + list[12] + ')')
        xxfgg.html('非骨干：' + list[15] + '%(' + list[14] + ')')
        xxggNav.css('width', list[13] + '%')
        xxfggNav.css('width', list[15] + '%')
        xxTeacherNum.html(list[11])
        zxgg.html('骨干：' + list[18] + '%(' + list[17] + ')')
        zxfgg.html('非骨干：' + list[20] + '%(' + list[19] + ')')
        zxggNav.css('width', list[18] + '%')
        zxfggNav.css('width', list[20] + '%')
        zxTeacherNum.html(list[16])
        getTeacherYearList()
        getTeacherCoreChart()
      },
      function (err) {
        console.log(err)
        baseListLoading.hide()
        teacherCoreChartLoading.hide()
        teacherYearListLoading.hide()
      }
    )
  }

  // 教师学科占比
  var subjectTabList = $('#subjectTab >span')
  var subjectList = $('#subjectList')
  var subjectTabKey = '1'
  subjectTabList.click(function (event) {
    var target = $(event.target)
    var key = +target.attr('data-key')
    if (!key) return
    subjectTabList.each(function () {
      $(this).removeClass('active')
    })
    target.addClass('active')
    getBaseSubjectList((subjectTabKey = key))
  })
  getBaseSubjectList()
  function getBaseSubjectList() {
    console.log('教师学科占比tab', subjectTabKey)
    subjectList.empty()
    _post(
      'szpz_jllg_info_xk',
      {},
      function (result) {
        if (result.status !== 200) return
        var list = []
        var head = []
        for (var i = 0; i < result.data.length; i++) {
          var item = result.data[i]
          switch (+subjectTabKey) {
            case 1:
              // 全区
              list.push([item[3]].concat(item.slice(5, 14)))
              break
            case 2:
              // 小学
              list.push([item[3]].concat(item.slice(14, 23)))
              break
            case 3:
              // 初中
              list.push([item[3]].concat(item.slice(23, item.length)))
              break
            default:
            //
          }
        }
        switch (+subjectTabKey) {
          case 1:
            // 全区
            head = [result.header[3]].concat(result.header.slice(5, 14))
            break
          case 2:
            // 小学
            head = [result.header[3]].concat(result.header.slice(14, 23))
            break
          case 3:
            // 初中
            head = [result.header[3]].concat(
              result.header.slice(23, result.header.length)
            )
            break
          default:
          //
        }
        //  2025-01-08 start
        list = list.sort(function (a, b) {
          return +a[5] > +b[5] ? -1 : 1
        })
        //  2025-01-08 end
        console.log('教师学科占比', head, list)
        for (var i = 0; i < list.length; i++) {
          var item = list[i]
          //  2025-01-08 start
          for (var key in _projectList) {
            key === item[0] && (item[0] = _projectList[key])
          }
          //  2025-01-08 end
          subjectList.append(
            '<div class="index-subject-row"><div class="flex-between index-subject-row-title"><h6>' +
              item[0] +
              '</h6><p><span>' +
              item[5] +
              '</span>人，占总人数比<span>' +
              item[6] +
              '%</span>，在编率<span>' +
              item[9] +
              '%</span></p> </div><div class="index-subject-row-nav"><div class="flex-start index-subject-row-ratio" style="width:' +
              item[6] +
              '%"><div class="index-subject-row-zb"><div class="index-subject-row-gg"></div></div><div class="index-subject-row-fzb"></div> </div></div></div>'
          )
        }
        // 触发进度条动画
        setTimeout(function () {
          // 单个学科人数占全科人数比例
          subjectList
            .find('.index-subject-row-zb')
            .each(function (index, event) {
              $(event).css(
                'width',
                (+list[index][3] / +list[index][5]) * 100 + '%'
              )
            })
          // 单个学科骨干占在编比例
          subjectList
            .find('.index-subject-row-gg')
            .each(function (index, event) {
              $(event).css(
                'width',
                (+list[index][2] / +list[index][3]) * 100 + '%'
              )
            })
          // 单个学科非在编
          subjectList
            .find('.index-subject-row-fzb')
            .each(function (index, event) {
              $(event).css(
                'width',
                (+list[index][4] / +list[index][5]) * 100 + '%'
              )
            })
        }, 100)
      },
      function (err) {
        console.log(err)
      }
    )
  }

  // 在编教师同一单位工作年限情况（人数）
  var durationChartLoading = $('#durationChartLoading')
  var teacherYearZrs = $('#teacherYearZrs')
  var teacherYearKjlrs = $('#teacherYearKjlrs')
  var teacherYearYjlrs = $('#teacherYearYjlrs')
  getDurationChart()
  function getDurationChart() {
    durationChartLoading.show()
    _post(
      'szpz_jllg_tydwgzqktj',
      {},
      function (result) {
        durationChartLoading.hide()
        if (result.error_code !== 0) return
        var list = result.data[0]
        teacherYearZrs.html(list[2])
        teacherYearKjlrs.html(list[3])
        teacherYearYjlrs.html(list[4])
        var data = []
        var title = {
          5: '3年以内',
          9: '4-6年',
          13: '7-9年',
          17: '10-12年',
          21: '13-15年',
          25: '16年以上',
          29: '离退休不足5年',
        }
        for (var i = 5; i < list.length; i += 4) {
          // 标题、总人数、占比、骨干人数、非骨干人数
          data.push([title[i], list[i], list[i + 1], list[i + 2], list[i + 3]])
        }
        console.log('在编教师同一单位工作年限情况（人数）', result, data)
        durationChartInit(data)
      },
      function (err) {
        console.log(err)
        durationChartLoading.hide()
      }
    )
  }

  // 在编教师教龄情况
  var teacherYearList = $('#teacherYearList')
  function getTeacherYearList() {
    var data = []
    var title = {
      31: '5年以内',
      34: '6-10年',
      37: '11-15年',
      40: '16-20年',
      43: '21年以上',
    }
    var total = 0
    teacherYearList.empty()
    for (var i = 0; i < baseInfo.data.length; i++) {
      var item = baseInfo.data[i]
      for (var j = 31; j < item.length; j += 3) {
        data.push([title[j], item[j], item[j + 1], item[j + 2]])
        total = total > item[j] ? total : item[j]
      }
    }
    console.log('在编教师教龄情况', data)
    total += 1000
    for (var i = 0; i < data.length; i++) {
      var item = data[i]
      teacherYearList.append(
        '<div class="flex-between index-year-row"><h6>' +
          item[0] +
          '</h6><div class="index-year-pro"><div class="module-right-point index-year-zb"></div><div class="module-right-point index-year-fgg"></div><div class="module-right-point index-year-gg"></div></div><p>' +
          item[1] +
          '</p></div>'
      )
    }
    // 触发进度条动画
    setTimeout(function () {
      // 在编教师
      teacherYearList.find('.index-year-zb').each(function (index, event) {
        $(event).css('width', (+data[index][1] / total) * 100 + '%')
      })
      // 骨干教师
      teacherYearList.find('.index-year-gg').each(function (index, event) {
        $(event).css('width', (+data[index][2] / total) * 100 + '%')
      })
      // 非骨干教师
      teacherYearList.find('.index-year-fgg').each(function (index, event) {
        $(event).css('width', (+data[index][3] / total) * 100 + '%')
      })
    }, 100)
  }

  // 在编骨干情况
  function getTeacherCoreChart() {
    var list = baseInfo.data[0]
    var data = []
    var head = baseInfo.header
    for (var i = 0; i < list.length; i++) {
      var item = list[i]
      if (i === 25) {
        data.push(
          [head[i].replace('在编骨干教师', ''), item],
          [head[i + 1].replace('在编骨干教师', ''), list[i + 1]],
          [head[i + 2].replace('在编骨干教师', ''), list[i + 2]],
          [head[i + 3].replace('在编骨干教师', ''), list[i + 3]],
          [head[i + 4].replace('在编骨干教师', ''), list[i + 4]],
          [head[i + 5].replace('在编骨干教师', ''), list[i + 5]]
        )
        break
      }
    }
    console.log('在编骨干情况', data)
    teacherCoreChartInit(data)
  }

  // 动态数据监测
  var schoolTabList = $('#schoolTabList > span')
  var schoolList = $('#schoolList')
  var schoolListLoading = $('#schoolListLoading')
  var schoolTabKey = '1'
  var schoolHead = $('#schoolHead')
  var schoolzblVal = ''
  var schoolkjlrsVal = ''
  var schoolyjlrsVal = ''
  var schoolDataList = []
  var schoolAllDataList = []
  var schoolDetailsDialog = $('#schoolDetailsDialog')
  var schoolDetailsDialogClose = $('#schoolDetailsDialogClose')
  var schoolHeadZbl = $('#schoolHeadZbl')
  var schoolHeadList = []
  schoolTabList.click(function (event) {
    var target = $(event.target)
    var key = +target.attr('data-key')
    if (!key) return
    schoolTabList.each(function () {
      $(this).removeClass('active')
    })
    schoolkjlrsVal = ''
    schoolyjlrsVal = ''
    schoolzblVal = ''
    schoolHead.find('img').each(function (index, item) {
      $(item).attr('src', webUrl+'/databoard/img/sort.png')
    })
    target.addClass('active')
    getSchoolList((schoolTabKey = key))
  })
  schoolHead.click(function (event) {
    var target = $(event.target)
    var key = target.attr('data-key')
    console.log(key)
    if (!key) return
    // 还原所有排序
    $(schoolHead.find('img')).each(function (index, item) {
      $(item).attr('src', webUrl+'/admin/databoard/img/sort.png')
    })
    switch (key) {
      // 在编率
      case 'schoolzbl':
        schoolkjlrsVal = ''
        schoolyjlrsVal = ''
        schoolzblVal = schoolzblVal === 'desc' ? 'asc' : 'desc'
        schoolDataList = schoolDataList.sort(function (a, b) {
          return schoolzblVal === 'desc'
            ? +a[12] > +b[12]
              ? -1
              : 1
            : +a[12] > +b[12]
            ? 1
            : -1
        })
        $(target.next()).attr(
          'src',
          schoolzblVal === 'desc' ? webUrl+'/databoard/img/desc.png' : webUrl+'/databoard/img/asc.png'
        )
        break
      // 可交流人数
      case 'schoolkjlrs':
        schoolzblVal = ''
        schoolyjlrsVal = ''
        schoolkjlrsVal = schoolkjlrsVal === 'desc' ? 'asc' : 'desc'
        schoolDataList = schoolDataList.sort(function (a, b) {
          return schoolkjlrsVal === 'desc'
            ? +a[14] > +b[14]
              ? -1
              : 1
            : +a[14] > +b[14]
            ? 1
            : -1
        })
        $(target.next()).attr(
          'src',
          schoolkjlrsVal === 'desc' ? webUrl+'/databoard/img/desc.png' : webUrl+'/databoard/img/asc.png'
        )
        break
      // 应交流人数
      case 'schoolyjlrs':
        schoolzblVal = ''
        schoolkjlrsVal = ''
        schoolyjlrsVal = schoolyjlrsVal === 'desc' ? 'asc' : 'desc'
        schoolDataList = schoolDataList.sort(function (a, b) {
          return schoolyjlrsVal === 'desc'
            ? +a[15] > +b[15]
              ? -1
              : 1
            : +a[15] > +b[15]
            ? 1
            : -1
        })
        $(target.next()).attr(
          'src',
          schoolyjlrsVal === 'desc' ? webUrl+'/databoard/img/desc.png' : webUrl+'/databoard/img/asc.png'
        )
        break
      default:
      //
    }
    updateSchoolList()
  })
  getSchoolList(true)
  function getSchoolList(isInit) {
    schoolListLoading.show()
    _post(
      'szpz_jllg_dtsjjc',
      {},
      function (result) {
        schoolListLoading.hide()
        console.log('动态数据监测', result)
        if (result.status !== 200) return
        schoolHeadList = result.header
        schoolAllDataList = result.data
        if (isInit) {
          schoolzblVal = 'desc'
          schoolHeadZbl.attr('src', webUrl+'/databoard/img/desc.png')
          schoolAllDataList = schoolAllDataList.sort(function (a, b) {
            return +a[12] > +b[12] ? -1 : 1
          })
        }
        updateSchoolList()
      },
      function (err) {
        console.log(err)
        schoolListLoading.hide()
      }
    )
  }
  function updateSchoolList() {
    schoolDataList = []
    switch (+schoolTabKey) {
      case 1:
        // 全区
        schoolDataList = schoolAllDataList
        break
      case 2:
        // 小学
        for (var i = 0; i < schoolAllDataList.length; i++) {
          var item = schoolAllDataList[i]
          if (item[5] === '小学' && item[7] !== '是') {
            schoolDataList.push(item)
          }
        }
        break
      case 3:
        // 中学
        for (var i = 0; i < schoolAllDataList.length; i++) {
          var item = schoolAllDataList[i]
          if (item[5] === '初中' && item[7] !== '是') {
            schoolDataList.push(item)
          }
        }
        break
      case 4:
        // 集团
        for (var i = 0; i < schoolAllDataList.length; i++) {
          var item = schoolAllDataList[i]
          if (item[7] === '是' || item[8] === '是') {
            schoolDataList.push(item)
          }
        }
        break
      default:
      //
    }
    schoolList.empty()
    for (var i = 0; i < schoolDataList.length; i++) {
      var item = schoolDataList[i]
      schoolList.append(
        '<div class="flex-start index-monitor-tr" data-key="' +
          item[4] +
          '-' +
          item[5] +
          '"><div class="single-text-hidden" title="' +
          item[4] +
          '">' +
          item[4] +
          '</div><div>' +
          item[5] +
          '</div><div class="flex-center">' +
          item[12] +
          '% <img src="'+webUrl+'/databoard/img/' +
          (+item[12] - +orgRatioVal > 0.5
            ? 'up'
            : Math.abs(+item[12] - +orgRatioVal) < 0.5
            ? 'equal'
            : 'down') +
          '.png" alt=""></div><div>' +
          item[14] +
          '</div><div>' +
          item[15] +
          '</div><div>' +
          item[18] +
          '</div><div><div class="flex-start index-monitor-nav">' +
          '<span style="width:' +
          +item[13] +
          '%"></span><span style="width:' +
          +item[14] +
          '%"></span><span style="width:' +
          +item[15] +
          '%"></span><span style="width:' +
          +item[16] +
          '%"></span><span style="width:' +
          +item[17] +
          '%"></span></div></div><div><img src="'+webUrl+'/databoard/img/no-' +
          (i > 3 ? 4 : i + 1) +
          '.png" alt=""><span>' +
          (i + 1) +
          '</span></div></div>'
      )
    }
  }

  // 单个学校点击
  var schoolRow = []
  var schoolDialogTotal = $('#schoolDialogTotal')
  var schoolDialogKjlrs = $('#schoolDialogKjlrs')
  var schoolDialogYjlrs = $('#schoolDialogYjlrs')
  var schoolDialogYearList = $('#schoolDialogYearList')
  var schoolTitle = $('#schoolTitle')
  schoolList.click(function (event) {
    var target = $(event.target).closest('.index-monitor-tr')
    var key = target.attr('data-key')
    console.log(key)
    if (!key) return
    for (var i = 0; i < schoolDataList.length; i++) {
      var item = schoolDataList[i]
      if (item[4] + '-' + item[5] === key) {
        schoolRow = item
        break
      }
    }
    console.log('单个学校数据', schoolRow)
    schoolDetailsDialog.show()
    schoolTitle.html(schoolRow[4] + '-' + schoolRow[5])
    updateSchoolDurationChart()
    updateSchoolSubjectList()
    updateSchoolDialogYearList()
    updateSchoolCoreChart()
  })
  schoolDetailsDialogClose.click(function () {
    schoolDetailsDialog.hide()
  })

  // 单个学校在编教师同单一单位工作年限情况
  var schoolWorkYearChartLoading = $('#schoolWorkYearChartLoading')
  function updateSchoolDurationChart() {
    var title = {
      12: '3年以内',
      15: '4-6年',
      18: '7-9年',
      21: '10-12年',
      24: '13-15年',
      27: '16年以上',
      30: '离退休不足5年',
    }
    var data = []
    schoolDialogTotal.html(0)
    schoolDialogKjlrs.html(0)
    schoolDialogYjlrs.html(0)
    for (var key in title) {
      data.push([title[key], 0, 0, 0])
    }
    schoolWorkYearChartInit(data)
    schoolWorkYearChartLoading.show()
    _post(
      'szpz_jllg_dtsjjc_tg',
      {},
      function (result) {
        schoolWorkYearChartLoading.hide()
        if (result.status !== 200) return
        var list = result.data
        var res = []
        for (var i = 0; i < list.length; i++) {
          var item = list[i]
          // 学校名与学段都要匹配
          if (item[5] === schoolRow[4] && item[6] === schoolRow[5]) {
            res = item
            break
          }
        }
        data = []
        for (var i = 12; i < res.length; i += 3) {
          // 标题、总人数、占比、骨干人数
          data.push([title[i], res[i], res[i + 1], res[i + 2]])
        }
        console.log('单个学校在编教师同单一单位工作年限情况', data, res)
        schoolDialogTotal.html(res[7])
        schoolDialogKjlrs.html(res[10])
        schoolDialogYjlrs.html(res[11])
        schoolWorkYearChartInit(data)
      },
      function (err) {
        console.log(err)
        schoolWorkYearChartLoading.hide()
      }
    )
  }

  // 单个学校教师学科占比
  var schoolDialogSubjectListLoading = $('#schoolDialogSubjectListLoading')
  var schoolDialogSubjectList = $('#schoolDialogSubjectList')
  function updateSchoolSubjectList() {
    schoolDialogSubjectList.empty()
    schoolDialogSubjectListLoading.show()
    _post(
      'szpz_jllg_dtsjjc_xk',
      {},
      function (result) {
        schoolDialogSubjectListLoading.hide()
        if (result.status !== 200) return
        var list = result.data
        var res = []
        var total = 0
        for (var i = 0; i < list.length; i++) {
          var item = list[i]
          // 学校名与学段都要匹配
          if (item[5] === schoolRow[4] && item[6] === schoolRow[5]) {
            res.push(item)
            // 在编教师+非在编教师 = 总教师数
            total += +item[10] + +item[11]
          }
        }
        // 2025-01-08 start
        res = res.sort(function (a, b) {
          return +a[10] + +a[11] > +b[10] + +b[11] ? -1 : 1
        })
        // 2025-01-08 end
        console.log('单个学校教师学科占比', res, total)
        for (var i = 0; i < res.length; i++) {
          var item = res[i]
          // 单科教师数
          var subjectNum = +item[10] + +item[11]
          var ratio = (subjectNum / total) * 100
          //  2025-01-08 start
          for (var key in _projectList) {
            key === item[7] && (item[7] = _projectList[key])
          }
          //  2025-01-08 end
          schoolDialogSubjectList.append(
            '<div class="index-subject-row"><div class="flex-between index-subject-row-title"><h6>' +
              item[7] +
              '</h6><p><span>' +
              subjectNum +
              '</span>人，占校人数比<span>' +
              ratio.toFixed(2) +
              '%</span>，在编率<span>' +
              item[14] +
              '%</span></p> </div><div class="index-subject-row-nav"><div class="flex-start index-subject-row-ratio" style="width:' +
              ratio +
              '%"><div class="index-subject-row-zb"><div class="index-subject-row-gg"></div></div><div class="index-subject-row-fzb"></div> </div></div></div>'
          )
        }
        // 触发进度条动画
        setTimeout(function () {
          // 单个学科人数占全科人数比例
          schoolDialogSubjectList
            .find('.index-subject-row-zb')
            .each(function (index, event) {
              $(event).css(
                'width',
                (+res[index][10] / (+res[index][10] + +res[index][11])) * 100 +
                  '%'
              )
            })
          // 单个学科骨干占在编比例
          schoolDialogSubjectList
            .find('.index-subject-row-gg')
            .each(function (index, event) {
              $(event).css(
                'width',
                (+res[index][9] / +res[index][10]) * 100 + '%'
              )
            })
          // 单个学科非在编
          schoolDialogSubjectList
            .find('.index-subject-row-fzb')
            .each(function (index, event) {
              $(event).css(
                'width',
                (+res[index][11] / (+res[index][10] + +res[index][11])) * 100 +
                  '%'
              )
            })
        }, 100)
      },
      function (err) {
        console.log(err)
        schoolDialogSubjectListLoading.hide()
      }
    )
  }

  // 单个学校在编教师教龄情况
  function updateSchoolDialogYearList() {
    schoolDialogYearList.empty()
    var yearList = []
    var yearTitle = {
      19: '5年以内',
      22: '6-10年',
      25: '11-15年',
      28: '16-20年',
      31: '21年以上',
    }
    var yearTotal = 0
    schoolDialogYearList.empty()
    for (var key in yearTitle) {
      for (var i = 19; i < schoolRow.length; i++) {
        if (i === +key) {
          var item = schoolRow[i]
          yearList.push([
            yearTitle[key],
            item,
            schoolRow[i + 1],
            schoolRow[i + 2],
          ])
          yearTotal = yearTotal > item ? yearTotal : item
        }
      }
    }
    console.log('单个学校在编教师教龄情况', yearList, yearTotal)
    yearTotal += 10
    for (var i = 0; i < yearList.length; i++) {
      var item = yearList[i]
      schoolDialogYearList.append(
        '<div class="flex-between index-year-row"><h6>' +
          item[0] +
          '</h6><div class="index-year-pro"><div class="module-right-point index-year-zb"></div><div class="module-right-point index-year-gg"></div><div class="module-right-point index-year-fgg"></div></div><p>' +
          item[1] +
          '</p></div>'
      )
    }
    // 触发进度条动画
    setTimeout(function () {
      // 在编教师
      schoolDialogYearList.find('.index-year-zb').each(function (index, event) {
        $(event).css('width', (+yearList[index][1] / yearTotal) * 100 + '%')
      })
      // 骨干教师
      schoolDialogYearList.find('.index-year-gg').each(function (index, event) {
        $(event).css('width', (+yearList[index][2] / yearTotal) * 100 + '%')
      })
      // 非骨干教师
      schoolDialogYearList
        .find('.index-year-fgg')
        .each(function (index, event) {
          $(event).css('width', (+yearList[index][3] / yearTotal) * 100 + '%')
        })
    }, 100)
  }

  // 单个学校在编骨干情况
  function updateSchoolCoreChart() {
    var data = [['总人数', schoolRow[18]]]
    for (var i = 34; i < schoolRow.length; i++) {
      var item = schoolRow[i]
      data.push([schoolHeadList[i].replace('在编骨干教师', ''), item])
    }
    console.log('单个学校在编骨干情况', data)
    teacherSchoolCoreChartInit(data)
  }

  // 各学科交流轮岗人数情况
  var achievementTabList = $('#achievementTab > span')
  achievementTabList.click(function (event) {
    var target = $(event.target)
    var key = +target.attr('data-key')
    if (!key) return
    achievementTabList.each(function () {
      $(this).removeClass('active')
    })
    target.addClass('active')
  })
  var rotationTotal = $('#rotationTotal')
  var rotationRatio = $('#rotationRatio')
  var rotationGgTotal = $('#rotationGgTotal')
  var rotationGgRatio = $('#rotationGgRatio')
  var rotationXld = $('#rotationXld')
  var rotationList = $('#rotationList')
  var rotationListLoading = $('#rotationListLoading')
  function getRotationList() {
    rotationListLoading.hide()
    // ajax
    setTimeout(function () {
      rotationListLoading.hide()
      var result = {}
      console.log('各学科交流轮岗人数情况', result)
    }, 1000)
  }

  // 学校交流轮岗人数排名
  var rotationRankTabList = $('#rotationRankTab > span')
  rotationRankTabList.click(function (event) {
    var target = $(event.target)
    var key = +target.attr('data-key')
    if (!key) return
    rotationRankTabList.each(function () {
      $(this).removeClass('active')
    })
    target.addClass('active')
  })

  var detailsBtn = $('#detailsBtn')
  var changeDetailsDialog = $('#changeDetailsDialog')
  var changeDetailsDialogClose = $('#changeDetailsDialogClose')
  detailsBtn.click(function () {
    changeDetailsDialog.show()
  })
  changeDetailsDialogClose.click(function () {
    changeDetailsDialog.hide()
  })
})
